Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 154 - Recycling / 154.cpp
blob77faa07c1997aa29df0c8913ab80d6e8843f454c
1 /*
2 Problem: 154 - Recycling
3 Andrés Mejía-Posada (andmej@gmail.com)
4 */
5 using namespace std;
6 #include <algorithm>
7 #include <iostream>
8 #include <iterator>
9 #include <sstream>
10 #include <fstream>
11 #include <cassert>
12 #include <climits>
13 #include <cstdlib>
14 #include <cstring>
15 #include <string>
16 #include <cstdio>
17 #include <vector>
18 #include <cmath>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
26 #define D(x) cout << #x " is " << x << endl
28 vector<int> score;
29 vector<string> lines;
31 int diff(string a, string b){
32 map<char, char> ma, mb;
33 for (int i=0; i<20; i += 4){
34 ma[a[i]] = a[i+2];
35 mb[b[i]] = b[i+2];
37 const string letters = "bogry";
38 int ans = 0;
39 for (int i=0; i<letters.size(); ++i){
40 ans += (ma[letters[i]] != mb[letters[i]]);
42 return ans;
45 int main(){
46 string s;
47 while (getline(cin, s) && s != "#"){
48 lines.clear();
49 lines.push_back(s);
50 while (getline(cin, s) && s[0] != 'e'){
51 lines.push_back(s);
53 int n = lines.size();
54 score.resize(n);
55 for (int i=0; i<n; ++i){
56 score[i] = 0;
57 for (int j=0; j<n; ++j){
58 score[i] += diff(lines[i], lines[j]);
61 printf("%d\n", min_element(score.begin(), score.end()) - score.begin() + 1);
63 return 0;